package com.ssy.lingxi.member.merchant.serviceimpl.web;

import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.OrganizationPageVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberRegisterTagVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberRightScoreVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.UserDetailVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberOrganizationQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.manage.request.MemberAndRoleIdVO;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberCacheService;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberDetailService;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberLevelConfigService;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberRegisterDetailService;
import com.ssy.lingxi.member.merchant.service.web.IMemberCommonBusinessService;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 会员“首页”服务接口实现类
 * @author 万宁
 * @version 2.0.0
 * @date 2020-10-23
 */
@Service
public class MemberCommonBusinessServiceImpl implements IMemberCommonBusinessService {
    @Resource
    private IBaseMemberCacheService memberCacheService;

    @Resource
    private IBaseMemberRegisterDetailService baseMemberRegisterDetailService;

    @Resource
    private IBaseMemberLevelConfigService baseMemberLevelConfigService;

    @Resource
    private IBaseMemberDetailService baseMemberDetailService;

    /**
     * 查询会员平台权益积分、上级会员下的权益积分
     * @param headers Http头部信息
     * @param idVO 接口参数
     * @return 查询结果
     */
    @Override
    public Wrapper<MemberRightScoreVO> getMemberRightPoint(HttpHeaders headers, MemberAndRoleIdVO idVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberLevelConfigService.getMemberRightPoint(idVO.getMemberId(), idVO.getRoleId(), loginUser.getMemberId(), loginUser.getMemberRoleId());
    }

    /**
     * 查询会员标签注册资料
     *
     * @param headers Http头部信息
     * @return 查询结果
     */
    @Override
    public Wrapper<MemberRegisterTagVO> getMemberRegisterTagDetail(HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberRegisterDetailService.getMemberRegisterTagDetail(loginUser.getMemberId());
    }

    /**
     * 查询用户注册资料
     *
     * @param headers Http头部信息
     * @return 查询结果
     */
    @Override
    public Wrapper<UserDetailVO> getUserDetail(HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberRegisterDetailService.getUserDetail(loginUser.getUserId());
    }

    /**
     * 分页查询会员组织机构
     *
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @Override
    public Wrapper<PageData<MemberOrganizationQueryVO>> pageMemberOrganizations(HttpHeaders headers, OrganizationPageVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return baseMemberDetailService.pageMemberOrganizations(loginUser.getMemberId(), pageVO.getCode(), pageVO.getTitle(), pageVO.getCurrent(), pageVO.getPageSize());
    }
}
